export default {
  /*formateDate: (time) => {
    if (!time) return '';
    let timeO = new Date(time);
    return '' +
      timeO.getFullYear() +
      '-' +
      padLeftZero(timeO.getMonth() + 1) +
      '-' +
      padLeftZero(timeO.getDate()) +
      ' ' +
      padLeftZero(timeO.getHours()) +
      ':' +
      padLeftZero(timeO.getMinutes()) +
      ':' +
      padLeftZero(timeO.getSeconds())
  }*/
  formatDate(date, fmt = 'yyyy-MM-dd hh:mm:ss') {
    // 正则替换对应年月日
    if (/(y+)/.test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    let o = {
      'M+': date.getMonth() + 1, // M+ 匹配 M 至少一次
      'd+': date.getDate(),
      'h+': date.getHours(),
      'm+': date.getMinutes(),
      's+': date.getSeconds()
    };
    for (let k in o) {
      if (new RegExp(`(${k})`).test(fmt)) {
        let str = o[k] + '';
        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
      }
    }
    return fmt;
  },

  pagination: function (data, callback) {
    return {
      onChange: (current) => {
        callback(current)
      },
      current: data.result.page,
      pageSize: data.result.page_size,
      total: data.result.total_count,
      showTotal: () => {
        return `共 ${data.result.total_count} 条`
      },
      showQuickJumper: true
    }
  }


}

// function padLeftZero (num) {
//   return num >=10? num: '0' + num;
// }
function padLeftZero(str) {
  return ('00' + str).substr(str.length);
}
